/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DialogoReporteGastosReencauches.java
 *
 * Created on 06-mar-2013, 14:44:01
 */
package com.camachosanchez.gui;

import com.camachosanchez.reportes.ReporteReencauches;
import com.camachosanchez.util.GUIUtil;
import java.util.Date;

/**
 *
 * @author Rolando
 */
public class DialogoReporteGastosReencauches extends javax.swing.JDialog {

    /** Creates new form DialogoReporteGastosReencauches */
    public DialogoReporteGastosReencauches(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        dateInicio.setDate(new Date());
        dateFin.setDate(new Date());
        setSize(380, 150);
//        dateInicio.requestFocusInWindow();
        setLocationRelativeTo(null);
        GUIUtil.addEscapeKey(this);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlContenedor = new javax.swing.JPanel();
        btnMensaje = new javax.swing.JLabel();
        pnlFechas = new javax.swing.JPanel();
        lblInicio = new javax.swing.JLabel();
        dateInicio = new com.toedter.calendar.JDateChooser();
        lblFin = new javax.swing.JLabel();
        dateFin = new com.toedter.calendar.JDateChooser();
        jToolBar1 = new javax.swing.JToolBar();
        jPanel1 = new javax.swing.JPanel();
        btnGenerarReporte = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(".:: Gastos en Reencauches ::.");
        setBackground(new java.awt.Color(231, 239, 247));
        setResizable(false);

        pnlContenedor.setBackground(new java.awt.Color(231, 239, 247));
        pnlContenedor.setLayout(new java.awt.GridLayout(2, 1, 4, 4));

        btnMensaje.setText("<html>Seleccione un intervalo de fechas para ver los detalles de gastos asociados a <u>reencauches</u>.");
        btnMensaje.setBorder(javax.swing.BorderFactory.createEmptyBorder(2, 8, 0, 0));
        pnlContenedor.add(btnMensaje);

        pnlFechas.setOpaque(false);

        lblInicio.setText("Inicio:");
        pnlFechas.add(lblInicio);

        dateInicio.setDateFormatString("dd/MM/yyyy");
        dateInicio.setMaxSelectableDate(new Date());
        dateInicio.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                dateInicioPropertyChange(evt);
            }
        });
        pnlFechas.add(dateInicio);

        lblFin.setText("Fin:");
        pnlFechas.add(lblFin);

        dateFin.setDateFormatString("dd/MM/yyyy");
        dateFin.setMaxSelectableDate(new Date());
        pnlFechas.add(dateFin);

        pnlContenedor.add(pnlFechas);

        getContentPane().add(pnlContenedor, java.awt.BorderLayout.CENTER);

        jToolBar1.setBackground(new java.awt.Color(255, 255, 255));
        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.setMinimumSize(new java.awt.Dimension(63, 25));
        jToolBar1.setPreferredSize(new java.awt.Dimension(63, 30));

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setMinimumSize(new java.awt.Dimension(69, 25));
        jPanel1.setPreferredSize(new java.awt.Dimension(383, 25));
        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 2, 2));

        btnGenerarReporte.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/camachosanchez/recursos/pdf.png"))); // NOI18N
        btnGenerarReporte.setText("Imprimir");
        btnGenerarReporte.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        btnGenerarReporte.setContentAreaFilled(false);
        btnGenerarReporte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGenerarReporteActionPerformed(evt);
            }
        });
        jPanel1.add(btnGenerarReporte);

        jToolBar1.add(jPanel1);

        getContentPane().add(jToolBar1, java.awt.BorderLayout.PAGE_START);

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void dateInicioPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_dateInicioPropertyChange
// TODO add your handling code here:
    if (evt.getPropertyName().compareTo("date") == 0) {
        dateFin.setMinSelectableDate(dateInicio.getDate());
    }
}//GEN-LAST:event_dateInicioPropertyChange

private void btnGenerarReporteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGenerarReporteActionPerformed
// TODO add your handling code here:
    final DialogoCargando dlg = new DialogoCargando(Principal.getInstance(), true);
    Thread hilo = new Thread() {

        @Override
        public void run() {
            try {
                ReporteReencauches reporteR = new ReporteReencauches();
                reporteR.generarReporte(dateInicio.getDate(), dateFin.getDate());
            } finally {
                dlg.dispose();
            }
        }
    };
    hilo.start();
    dlg.setVisible(true);
}//GEN-LAST:event_btnGenerarReporteActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnGenerarReporte;
    private javax.swing.JLabel btnMensaje;
    private com.toedter.calendar.JDateChooser dateFin;
    private com.toedter.calendar.JDateChooser dateInicio;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JLabel lblFin;
    private javax.swing.JLabel lblInicio;
    private javax.swing.JPanel pnlContenedor;
    private javax.swing.JPanel pnlFechas;
    // End of variables declaration//GEN-END:variables
}
